<?php
/**
 * @version $Id: install.easycomments.php 283 2007-12-02 22:34:46Z elkuku $
 * @package EasyComments
 * EasyComments - A Joomla Comment Component
 * Based on akocomment
 * @license Released under the terms of the GNU General Public License (see LICENSE.php in the Joomla! root directory)
 * @Achim Raji (aka cybergurk) - David Jardin (aka SniperSister) - Cedric May - Siegmund Langsch (aka langsch2)
 **/

( defined( '_JEXEC' ) ) or ( defined( '_VALID_MOS' ) ) or die( 'Restricted access' );

function com_install() {
  	global $_VERSION, $database, $mosConfig_absolute_path, $mosConfig_lang;

 	# Install Mambot 

  	$botPath = "";
	if($_VERSION->RELEASE == "1.5"){
		$botPath = "plugins";
	} else {
		$botPath = "mambots";
	}

	$database->setQuery ( "SELECT ordering FROM #__$botPath ORDER BY ordering DESC LIMIT 1,1 " );
	$paginationorder = $database->loadResult() + 1;
	$botorder = $paginationorder + 2;
	
	if($_VERSION->RELEASE == "1.5"){
	
  		$database->setQuery( "UPDATE #__$botPath SET ordering = '$paginationorder' WHERE element='pagebreak'");
	
	} else {
		
  		$database->setQuery( "UPDATE #__$botPath SET ordering = '$paginationorder' WHERE element='mospaging'");

	}
	
	$database->query();
	

	$database->setQuery( "INSERT INTO #__$botPath (`name`, `element`, `folder`, `access`, `ordering`, `published`, `iscore`, `client_id`, `checked_out`, `checked_out_time`, `params`) VALUES ('EasyComments', 'easycomments_bot', 'content', 0, $botorder, 1, 0, 0, 0, '0000-00-00 00:00:00', '');");
	$database->query();
  	
  	$adminDir = dirname(__FILE__);
	if	(!file_exists($mosConfig_absolute_path."/".$botPath."/content/easycomments_bot.php"))
	{
    rename( $adminDir. "/mambot/easycomments_bot.php", $mosConfig_absolute_path."/".$botPath."/content/easycomments_bot.php");
	}
	if	(!file_exists($mosConfig_absolute_path."/".$botPath."/content/easycomments_bot.xml"))
	{
    rename( $adminDir. "/mambot/easycomments_bot.xml", $mosConfig_absolute_path."/".$botPath."/content/easycomments_bot.xml");
	}

	# Include language-file

	if (file_exists($mosConfig_absolute_path.'/components/com_easycomments/languages/'.$mosConfig_lang.'.php')) {

		include_once($mosConfig_absolute_path.'/components/com_easycomments/languages/'.$mosConfig_lang.'.php');

	} else {

		include_once($mosConfig_absolute_path.'/components/com_easycomments/languages/english.php');

	}
	
    # Set up new icons for admin menu
    $database->setQuery("UPDATE #__components SET admin_menu_img='../components/com_easycomments/images/ec_user.gif' WHERE admin_menu_link='option=com_easycomments&task=comments'");
    $iconresult[0] = $database->query();
    $database->setQuery("UPDATE #__components SET admin_menu_img='../components/com_easycomments/images/ec_settings.gif' WHERE admin_menu_link='option=com_easycomments&task=settings'");
    $iconresult[1] = $database->query();
    $database->setQuery("UPDATE #__components SET admin_menu_img='../components/com_easycomments/images/ec_info.gif' WHERE admin_menu_link='option=com_easycomments&task=about'");
    $iconresult[2] = $database->query();
	$database->setQuery("UPDATE #__components SET admin_menu_img='../components/com_easycomments/images/ec_icon.gif' WHERE admin_menu_link='option=com_easycomments'");
    $iconresult[3] = $database->query();
	$database->setQuery("UPDATE #__components SET name='"._EASYCOMMENTS_INSTALL_MENU_SHOW."' WHERE admin_menu_link='option=com_easycomments&task=comments'");
    $iconresult[4] = $database->query();
	$database->setQuery("UPDATE #__components SET name='"._EASYCOMMENTS_INSTALL_MENU_SETTINGS."' WHERE admin_menu_link='option=com_easycomments&task=settings'");
    $iconresult[5] = $database->query();
	$database->setQuery("UPDATE #__components SET name='"._EASYCOMMENTS_INSTALL_MENU_ABOUT."' WHERE admin_menu_link='option=com_easycomments&task=about'");
    $iconresult[6] = $database->query();
	$database->setQuery("UPDATE #__components SET name='"._EASYCOMMENTS_INSTALL_MENU_MIGRATE."' WHERE admin_menu_link='option=com_easycomments&task=migrate'");
    $iconresult[7] = $database->query();
     $database->setQuery("UPDATE #__components SET admin_menu_img='../components/com_easycomments/images/table.gif' WHERE admin_menu_link='option=com_easycomments&task=migrate'");
    $iconresult[8] = $database->query();

	# Show installation result to user
	echo"<style type='text/css'>
		<!--
			.easycomments_install_success_message {
				text-align: left;
				background: url(components/com_easycomments/images/box.png) no-repeat;
				color: #ffffff;
				width: 549px;
				height: 259px;
				padding-top: 62px; padding-left: 20px;
			}
			.easycomments_install_nosuccess_message {
				text-align: left;
				background: url(components/com_easycomments/images/box_nosuccess.png) no-repeat;
				color: #ffffff;
				width: 549px;
				height: 259px;
				padding-top: 62px; padding-left: 20px;
			}
		-->
	</style>
	
	<div align='center'>";
		if(file_exists($mosConfig_absolute_path."/$botPath/content/easycomments_bot.php")) {
			echo "<div class='easycomments_install_success_message'>
				<span style='font-size: 24px;'>"._EASYCOMMENTS_INSTALL_SUCCESS_A."</span><br />
					"._EASYCOMMENTS_INSTALL_SUCCESS_B."<br /><br /><br /><br />
				<span style='color: #6e6e6e;'>
					"._EASYCOMMENTS_INSTALL_INFO."
				</span>
			</div>";
		} else {
			echo "<div class='easycomments_install_nosuccess_message'>
				<span style='font-size: 24px;'>"._EASYCOMMENTS_INSTALL_ERROR_A."</span><br />
					"._EASYCOMMENTS_INSTALL_ERROR_B."<br /><br /><br /><br />
				<span style='color: #6e6e6e;'>
					"._EASYCOMMENTS_INSTALL_ERROR_INFO."
				</span>
			</div>";
		} 
	echo "</div>";

}



?>